home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_08_09 / 8n09115a < prev    next >
Text File  |  1990-06-18  |  2KB  |  82 lines

  1.  
  2.  
  3. *******
  4. Listing 3:
  5.  
  6. double cvd(s) 
  7. char *s;       
  8. /* Function to read an 8 yte string*/
  9. /* representing a BASIC floatwritten*/          
  10. /* by MKDS. Entry = string*/      
  11. /* Return = value*/                 
  12.    {
  13.    double sum;                   
  14.                                  
  15.    double t, tt, div;              
  16.    int cnt, exp, pos, n, negative;   
  17.  
  18.      sum = 0;
  19.      exp = s[7];                 /*exponent*/
  20.      negative = s[6] & 0x80;     /*Save signbit*/
  21.      s[6] = s[6] & 0x7f;         /*Mask signbit*/
  22.      exp -= 0x81;                /*Subtract offset*/
  23.  
  24. /*   printf("\nExp:%d T:%4.4f",exp,t);  */
  25.      sum += t;
  26.      cnt = 7;
  27.      div = 128.0;
  28.      pos = 8;
  29.      while (cnt--)
  30.           {
  31.           n=s[pos];
  32.           tt=t/div;
  33. /*        printf("\n&d : n  4.4f t-t4.4f tt=%d.df",pos,n,t,tt);*/
  34.           sum += tt*n;
  35.           div *= 256;
  36.           --pos;
  37.           }
  38.      if (negative) 
  39.            sum = -sum;
  40.      return(sum);
  41.      }
  42.  
  43. double svs(s) 
  44. char *s;
  45. /* Function to read a 4 byte string */
  46. /* representing a BASIC float written */ 
  47. /* by MKSS. Entry = string */             
  48. /* Return = value */                   
  49.    {
  50.    double sum;                   
  51.    double t, tt, div;              
  52.    int cnt, exp, pos, n, negative;    
  53.      
  54.      sum = 0;                    
  55.      exp = s[3];                /*Exponent */              
  56.      negative = s[2] & 0x80;      /*Save signbit */
  57.      s[6] = s[2] & 0x7f;          /*Mask  */
  58.      exp -= 0x81;               /*Subtract offset */
  59.      t = pow(2.0, (double) exp);
  60. /*   printf("\nExp:% t:%4.4f",exp,t);   */
  61.      sum += t;
  62.      cnt = 3;
  63.      div = 128.0;
  64.      pos = 2;
  65.      while (cnt--) 
  66.           {
  67.           n = s[pos];
  68.           tt = t / div;
  69. /*        printf("/\n%d : n=%4.4f t=%4.4f tt-%4.4f",pos,n,t,tt);*/
  70.           sum += tt * n;
  71.           div /= 128;
  72.           --pos;
  73.           }
  74.      if (negative) 
  75.        sum = -sum;
  76.      return(sum);
  77.      }          
  78.  
  79. ********
  80.  
  81.  
  82.